package com.cdzy.controller;

import com.cdzy.common.ApiResponse;
import com.cdzy.pojo.LendList;
import com.cdzy.service.LendListService;
import jakarta.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 图书借阅表(LendList)表控制层
 *
 * @author makejava
 * @since 2025-04-01 10:04:21
 */
@RestController
@RequestMapping("/lendList")
@CrossOrigin
public class LendListController {
    /**
     * 服务对象
     */
    @Resource
    private LendListService lendListService;


    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    public ResponseEntity<LendList> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.lendListService.queryById(id));
    }



    /**
     * 新增数据
     *
     * @param lendList 实体
     * @return 新增结果
     */
    @PostMapping("/add")
    public ResponseEntity<LendList> add(@RequestBody LendList lendList) {
        return ResponseEntity.ok(this.lendListService.insert(lendList));
    }

    /**
     * 编辑数据
     *
     * @param lendList 实体
     * @return 编辑结果
     */
    @PutMapping("/edit")
    public ResponseEntity<LendList> edit(@RequestBody LendList lendList) {
        return ResponseEntity.ok(this.lendListService.update(lendList));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/delete/{id}")
    public ResponseEntity<Boolean> deleteById(@PathVariable Integer id) {
        return ResponseEntity.ok(this.lendListService.deleteById(id));
    }


    /**
     * 查询所有借阅记录
     * @return
     */
    @GetMapping("/list")
    public ApiResponse<?> list(){
        List<LendList> list = lendListService.getLendList();
        return ApiResponse.success(list);
    }

}

